package pl.un4giv3n.mightvsmagic.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

@NamedQueries({
	@NamedQuery(name="find.clanwar.by.attacker", query="select cw from ClanWar cw where attackerId=:attackerId"),
	@NamedQuery(name="find.clanwar.by.defender", query="select cw from ClanWar cw where defenderId=:defenderId"),
	@NamedQuery(name="find.current.clan.wars", query="select cw from ClanWar cw where finished=false and (defenderId=:clanId or attackerId=:clanId)"),
	@NamedQuery(name="find.old.clan.wars", query="select cw from ClanWar cw where finished=true and (defenderId=:clanId or attackerId=:clanId)")
})
@Entity
public class ClanWar {

	private Long id;
	/**
	 * attacking clan id
	 */
	private Long attackerId;
	private String attackerName;
	/**
	 * defending clan id
	 */
	private Long defenderId;
	private String defenderName;
	
	private List<ClanBattle> battles = new ArrayList<ClanBattle>();
	private long lastBattleTime;
	private Long winnerId;
	private String winnerName;
	private Long looserId;
	private String looserName;
	private boolean finished;
	private long gold;
	@GeneratedValue
	@Id
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Long getAttackerId() {
		return attackerId;
	}
	public void setAttackerId(Long attackerId) {
		this.attackerId = attackerId;
	}
	public Long getDefenderId() {
		return defenderId;
	}
	public void setDefenderId(Long defenderId) {
		this.defenderId = defenderId;
	}
	@OneToMany
	public List<ClanBattle> getBattles() {
		return battles;
	}
	public void setBattles(List<ClanBattle> battles) {
		this.battles = battles;
	}
	public long getLastBattleTime() {
		return lastBattleTime;
	}
	public void setLastBattleTime(long lastBattleTime) {
		this.lastBattleTime = lastBattleTime;
	}
	public Long getWinnerId() {
		return winnerId;
	}
	public void setWinnerId(Long winnerId) {
		this.winnerId = winnerId;
	}
	public String getWinnerName() {
		return winnerName;
	}
	public void setWinnerName(String winnerName) {
		this.winnerName = winnerName;
	}
	public Long getLooserId() {
		return looserId;
	}
	public void setLooserId(Long looserId) {
		this.looserId = looserId;
	}
	public String getLooserName() {
		return looserName;
	}
	public void setLooserName(String looserName) {
		this.looserName = looserName;
	}
	public boolean isFinished() {
		return finished;
	}
	public void setFinished(boolean finished) {
		this.finished = finished;
	}
	public String getAttackerName() {
		return attackerName;
	}
	public void setAttackerName(String attackerName) {
		this.attackerName = attackerName;
	}
	public String getDefenderName() {
		return defenderName;
	}
	public void setDefenderName(String defenderName) {
		this.defenderName = defenderName;
	}
	public long getGold() {
		return gold;
	}
	public void setGold(long gold) {
		this.gold = gold;
	}
}
